<template>
	<view class="content">
		<view class="menu-block">
			<view class="title-top">
				<view class="tips"></view>
				<view class="title">
					请填写基本信息
				</view>
			</view>
			<view class="form-item" v-if="id==8||id==9">
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">企业名称</view>
				</view>
				<view class="form-content" >
					<input v-model="form.comName" maxlength="10" type="text" placeholder-class="inputPlaceholder"
						placeholder="请填企业名称" class="form-ctrl" />
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item" v-if="id==8||id==9">
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">法人代表</view>
				</view>
				<view class="form-content" >
					<input v-model="form.name" maxlength="10" type="text" placeholder-class="inputPlaceholder"
						placeholder="请填法人代表" class="form-ctrl" />
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item" v-else>
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">真实姓名</view>
				</view>
				<view class="form-content" >
					<input v-model="form.name" maxlength="10" type="text" placeholder-class="inputPlaceholder"
						placeholder="请填真实姓名" class="form-ctrl" />
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">手机号码</view>
				</view>
				<view class="form-content">
					<input v-model="form.phone" maxlength="11" type="number" placeholder-class="inputPlaceholder"
						placeholder="请填写手机号码" class="form-ctrl"/>
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item" v-if="id==7">
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">申请人身份</view>
				</view>
				<view class="form-content">
					<picker class="form-ctrl" :range="identityData" range-key="name" :value="identityIndex"
						@change="bindIdentity">
						{{identityIndex==-1 ? "请选择申请人身份" : identityData[identityIndex]['name']}}
					</picker>
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view style="display: flex;flex-direction: row;">
					<view style="color: #C10A11;">*</view>
					<view class="form-label">营业执照登记注册地</view>
				</view>
				<view class="form-content">
					<picker class="form-ctrl" :range="areaData" range-key="name" :value="areaIndex"
						@change="bindArea">
						{{areaIndex==-1 ? "请选择营业执照登记注册地" : areaData[areaIndex]['name']}}
					</picker>
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
		</view>
		<view class="step" @click="handleSave">
			提交
		</view>
	</view>
</template>

<script>
	import {
		userAddApplyLoan
	} from '@/api/bussiness.js';
	import {
		validate
	} from '@/util/validate.js'
	export default {
		data() {
			return {
				form: {
					comName: '',
					name: '',
					phone: '',
					areaId: 0,
					identity: '',
				},
				areaData: [{
					id: 1,name: '肃州区',
				},
				{
					id: 2,name: '金塔县',
				},{
					id: 3,name: '瓜州县',
				},
				{
					id: 4,name: '肃北县',
				},
				{
					id: 5,name: '阿克塞县',
				},
				{
					id: 6,name: '玉门市',
				},
				{
					id: 7,name: '敦煌市',
				}],
				areaIndex: -1,
				identityData: [{
					id: 1,name: '城镇登记失业人员',
				},
				{
					id: 2,name: '就业困难人员（含残疾人）',
				},{
					id: 3,name: '退役军人',
				},
				{
					id: 4,name: '刑满释放人员',
				},
				{
					id: 5,name: '高校毕业生（含大学生村官和留学回国学生）',
				},
				{
					id: 6,name: '化解过剩产能企业职工和失业人员',
				},
				{
					id: 7,name: '返乡创业农民工',
				},
				{
					id: 8,name: '网络商户',
				},
				{
					id: 9,name: '脱贫人口',
				},
				{
					id: 10,name: '农村自主创业农民',
				}],
				identityIndex: -1,
				tabActive: 0,
				labelIndex: 0,
				rules: {
					name: {
						name: '真实姓名',
						required: true
					},
					phone: {
						name: '手机号',
						required: true,
						validator: function(value, form, callback) {
							if (!/^1[3-9][0-9]{9}$/.test(value)) {
								callback('请输入正确的手机号')
							}
							callback();
						}
					},
				},
				id: null,
			}
		},
		methods: {
			bindArea(e) {
				this.areaIndex = e.detail.value;
				this.form.areaId = this.areaData[this.areaIndex].id
			},
			bindIdentity(e) {
				this.identityIndex = e.detail.value;
				this.form.identity = this.identityData[this.identityIndex].name
			},
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			handleSave() {
				let form = JSON.parse(JSON.stringify(this.form));
				form.name = this.form.name
				form.phone = this.form.phone
				form.loanId = this.id
				if (validate(form, this.rules)) {
					uni.showLoading({
						title: '加载中',
						mask: true
					})
					userAddApplyLoan(form).then((res) => {
						uni.hideLoading()
						this.showToast(res, () => {
							this.navigate('/page_other/submit/bus_submit')
						})
					}).catch((res) => {
						uni.hideLoading()
						this.showToast('提交失败');
					})
				}
			}

		},
		onLoad(e) {
			//培训机构ID
			this.id = e.id
			console.log(this.id)
		},
		onReachBottom() {
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fafafa;
	}
	.title-top{
		display: flex;
		.tips{
			width: 18rpx;
			height: 32rpx;
			border-radius: 20rpx;
			background-color: #0256FF;
			margin: 16rpx 12rpx 0 0;
		}
		
		.title{
			font-weight: 900;
			font-size: 32rpx;
			line-height: 60rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 1;
			margin-bottom: 25rpx;
		}
		
	}
	.form-content {
		display: flex;
		flex-direction: column;
		// align-items: center;
		
		.form-ctrl {
			height: 100rpx;
			line-height: 100rpx;
			flex-grow: 1;
		}
		
		.arrow {
			flex-grow: 0;
			color: #999;
			font-size: 24rpx;
		}
	}
	.selected-area{
		font-size: 32rpx;
	}
	.form-item1 {
		display: flex;
		flex-direction: column;
		border-bottom: 1px solid #efefef;
		padding-top: 30rpx;
	
		.form-label {
			font-size: 28rpx;
			color: #999;
		}
	
		
	}
	.swiper-block {
		width: 100%;
		height: 280rpx;
		box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
		border-radius: 20rpx;
		.img{
			width: 100%;
			height: 100%;
		}
	}
	.content {
		width: 100%;
		padding: 30rpx;
		.step{
			width: 350rpx;
			height: 100rpx;
			display: flex;
			background-color: red;
			color: #fff;
			margin: 30rpx auto;
			border-radius: 60rpx;
			justify-content: center;
			align-items: center;
		}
		.menu-block {
			margin-top: 30rpx;
			background: #fff;
			border-radius: 12px;
			padding: 30rpx;
			.form-title {
				font-size: 36rpx;
				font-weight: bold;
			}
			
			.form-item {
				display: flex;
				flex-direction: column;
				border-bottom: 1px solid #efefef;
				padding-top: 30rpx;
			
				.form-label {
					font-size: 32rpx;
					color: #1A1A1A;
				}
			
				.form-content {
					display: flex;
					flex-direction: column;
					// align-items: center;
			
					.form-ctrl {
						height: 100rpx;
						line-height: 100rpx;
						flex-grow: 1;
					}
			
					.arrow {
						flex-grow: 0;
						color: #767676;
						font-size: 32rpx;
					}
				}
			}
			.title{
				font-weight: 900;
				font-size: 32rpx;
				line-height: 60rpx;
				width: 100%;
				color: #1A1A1A;
				overflow: hidden; 
				white-space: nowrap; 
				text-overflow: ellipsis;
			}
		}
	}
</style>